import React, { Component } from 'react';
import { ThemeContext } from '../context/themeContext';

class ContextApp extends Component {
    constructor(props) {
        super(props);
        this.state = {
            tm: {
                fontColor: '#00ff00',
                backgroundColor: '#ff0000'
            }
        };
        this.infChange = this.infChange.bind(this);
    }

    infChange(newObj) {
        const { tm } = this.state;
        const resObj = { ...tm, ...newObj };
        this.setState({ tm: resObj });
    }

    render() {
        const { tm } = this.state;
        const { children } = this.props;
        return <ThemeContext.Provider value={{ tm, infChange: this.infChange }}>{children}</ThemeContext.Provider>;
    }
}
export default ContextApp;
